<!-- 订单详情组件 -->
<template>
  <ContentWrap>
    <el-collapse v-model="activeNames">
      <el-collapse-item name="contractInfo">
        <template #title>
          <span class="text-base font-bold">基本信息</span>
        </template>
        <el-descriptions :column="4">
          <el-descriptions-item label="订单编号">{{ contract.no }}</el-descriptions-item>
          <el-descriptions-item label="订单名称">{{ contract.name }}</el-descriptions-item>
          <el-descriptions-item label="客户名称">{{ contract.customerName }}</el-descriptions-item>
          <el-descriptions-item label="客户订单编号">{{ contract.customerOrderNo }}</el-descriptions-item>
          <el-descriptions-item label="手工订单编号">{{ contract.manualOrderNo }}</el-descriptions-item>
          <el-descriptions-item label="店铺名称">{{ contract.storeName }}</el-descriptions-item>
          <el-descriptions-item label="店铺面积">{{ contract.storeArea }}</el-descriptions-item>
          <el-descriptions-item label="订单金额（元）">
            {{ erpPriceInputFormatter(contract.totalPrice) }}
          </el-descriptions-item>
          <el-descriptions-item label="订单类型">
            <dict-tag :type="DICT_TYPE.TRADE_ORDER_TYPE" :value="contract.orderType" />
          </el-descriptions-item>
          <el-descriptions-item label="订单状态">
            <dict-tag :type="DICT_TYPE.TRADE_ORDER_STATUS" :value="contract.orderStatus" />
          </el-descriptions-item>
          <el-descriptions-item label="交货方式">
            <dict-tag :type="DICT_TYPE.TRADE_DELIVERY_TYPE" :value="contract.deliveryType" />
          </el-descriptions-item>
          <el-descriptions-item label="联系人">
            {{ contract.contactName }}
          </el-descriptions-item>
          <el-descriptions-item label="联系电话">
            {{ contract.signContactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="收货地区">
            <el-cascader
              v-model = "areaId"
              :options="areaList"
              :props="defaultProps"
              class="w-1/2"
              disabled />
          </el-descriptions-item>
          <el-descriptions-item label="收货详细地址">
            {{ contract.detailAddress }}
          </el-descriptions-item>
          <el-descriptions-item label="下单时间">
            {{ formatDate(contract.orderDate) }}
          </el-descriptions-item>
          <el-descriptions-item label="约定发货时间">
            {{ formatDate(contract.shipTime) }}
          </el-descriptions-item>
          <el-descriptions-item label="约定到货时间">
            {{ formatDate(contract.deliveryTime) }}
          </el-descriptions-item>

          <el-descriptions-item label="业务员">
            {{ contract.signUserName }}
          </el-descriptions-item>
          <el-descriptions-item label="备注">
            {{ contract.remark }}
          </el-descriptions-item>

        </el-descriptions>
      </el-collapse-item>
      <el-collapse-item name="systemInfo">
        <template #title>
          <span class="text-base font-bold">系统信息</span>
        </template>
        <el-descriptions :column="4">
          <el-descriptions-item label="负责人">{{ contract.ownerUserName }}</el-descriptions-item>
          <el-descriptions-item label="最后跟进时间">
            {{ formatDate(contract.contactLastTime) }}
          </el-descriptions-item>
          <el-descriptions-item label="">&nbsp;</el-descriptions-item>
          <el-descriptions-item label="">&nbsp;</el-descriptions-item>
          <el-descriptions-item label="创建人">{{ contract.creatorName }}</el-descriptions-item>
          <el-descriptions-item label="创建时间">
            {{ formatDate(contract.createTime) }}
          </el-descriptions-item>
          <el-descriptions-item label="更新时间">
            {{ formatDate(contract.updateTime) }}
          </el-descriptions-item>
        </el-descriptions>
      </el-collapse-item>
    </el-collapse>
  </ContentWrap>
</template>
<script lang="ts" setup>
import { defaultProps, handleTree } from '@/utils/tree'
import * as ContractApi from '@/api/crm/contract'
import { formatDate } from '@/utils/formatTime'
import { DICT_TYPE } from '@/utils/dict'
import { erpPriceInputFormatter } from '@/utils'
import * as AreaApi from "@/api/system/area";

defineOptions({ name: 'ContractDetailsInfo' })
const { contract } =defineProps<{
  contract: ContractApi.ContractVO
}>()

const areaId = computed(() => {
  return contract.areaId;
});
const areaList = ref([]) // 地区列表
// 展示的折叠面板
const activeNames = ref(['contractInfo', 'systemInfo'])

/** 初始化 **/
onMounted(async () => {
  // 获得地区列表
  areaList.value = await AreaApi.getAreaTree()
})
</script>
